/*
 * io.c
 *
 *  Created on: 20/09/2008
 *      Author: kimi
 */

#include "lpc213x.h"
#include "cpu/io.h"
void io_SetOutputPin(unsigned char port, unsigned char pin) {
	if (port == 0)
		IODIR0 |= (1 << pin);
	else if (port == 1)
		IODIR1 |= (1 << pin);
}

void io_SetInputPin(unsigned char port, unsigned char pin) {
	if (port == 0)
		IODIR0 &= ~(1 << pin);
	else if (port == 1)
		IODIR1 &= ~(1 << pin);
}

void io_SetPin(unsigned char port, unsigned char pin) {
	if (port == 0)
		IOSET0 = (1 << pin);
	else if (port == 1)
		IOSET1 = (1 << pin);
}

void io_ClearPin(unsigned char port, unsigned char pin) {
	if (port == 0)
		IOCLR0 = (1 << pin);
	else if (port == 1)
		IOCLR1 = (1 << pin);
}

void io_TogglePin(unsigned char port, unsigned char pin) {
	if (io_ReadPin(port, pin))
		io_ClearPin(port, pin);
	else
		io_SetPin(port, pin);
}

unsigned char io_ReadPin(unsigned char port, unsigned char pin) {
	if (port == 0)
		return (IOPIN0 & (1 << pin));
	if (port == 1)
		return (IOPIN1 & (1 << pin));
	return 0;
}
